import requests
import time
from config.config import *

def send_feishu_message():
    # 1.创建富文本内容
    massage_data=[
        [
            {"tag":"text","text":f"项目名称：{PROJECT_NAME}"}
        ],
        [
            {"tag":"text","text":f"执行时间:{time.strftime('%Y-%m-%d %H:%M:%S')}"}
        ],
        [
            {"tag":"text","text":"详细信息："},
            {"tag":"a","text":"查看测试报告","href":REPORT_PATH}
        ]
    ]
    # 2.构建最终的消息体
    payload={
        "msg_type":"post",
        "content":{
            "post":{
                "zh_cn":{
                    "title":"自动化测试报告",
                    "content":massage_data
                }
            }
        }
    }
    # 3.发送请求（判断发送飞书消息开关是否打开，打开则可以发送，不开则不发送）
    if IS_SEND_FEISHU:
        response=requests.post(WEBHOOK,json=payload)
        return response

if __name__ == '__main__':
    send_feishu_message()


